<?php
// $Id: template.php,v 1.16.2.3 2010/05/11 09:41:22 goba Exp $

/**
 * Sets the body-tag class attribute.
 *
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
 */
function phptemplate_body_class($left, $right) {
  if ($left != '' && $right != '') {
    $class = 'sidebars';
  }
  else {
    if ($left != '') {
      $class = 'sidebar-left';
    }
    if ($right != '') {
      $class = 'sidebar-right';
    }
  }

  if (isset($class)) {
    print ' class="'. $class .'"';
  }
}

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function phptemplate_breadcrumb($breadcrumb) {
  if (!empty($breadcrumb)) {
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
  }
}

/**
 * Override or insert PHPTemplate variables into the templates.
 */
function phptemplate_preprocess_page(&$vars) {
  $vars['tabs2'] = menu_secondary_local_tasks();

  // Hook into color.module
  if (module_exists('color')) {
    _color_page_alter($vars);
  }
}

/**
 * Add a "Comments" heading above comments except on forum pages.
 */
function garland_preprocess_comment_wrapper(&$vars) {
  if ($vars['content'] && $vars['node']->type != 'forum') {
    $vars['content'] = '<h2 class="comments">'. t('Comments') .'</h2>'.  $vars['content'];
  }
}

/**
 * Returns the rendered local tasks. The default implementation renders
 * them as tabs. Overridden to split the secondary tasks.
 *
 * @ingroup themeable
 */
function phptemplate_menu_local_tasks() {
  return menu_primary_local_tasks();
}

/**
 * Returns the themed submitted-by string for the comment.
 */
function phptemplate_comment_submitted($comment) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $comment),
      '!datetime' => format_date($comment->timestamp)
    ));
}

/**
 * Returns the themed submitted-by string for the node.
 */
function phptemplate_node_submitted($node) {
  return t('!datetime — !username',
    array(
      '!username' => theme('username', $node),
      '!datetime' => format_date($node->created),
    ));
}

/**
 * Generates IE CSS links for LTR and RTL languages.
 */
function phptemplate_get_ie_styles() {
  global $language;

  $iecss = '<link type="text/css" rel="stylesheet" media="all" href="'. base_path() . path_to_theme() .'/fix-ie.css" />';
  if ($language->direction == LANGUAGE_RTL) {
    $iecss .= '<style type="text/css" media="all">@import "'. base_path() . path_to_theme() .'/fix-ie-rtl.css";</style>';
  }

  return $iecss;
}

function loopriz_garland_theme(&$existing, $type, $theme, $path)
{
  return array(    
    // tell Drupal what template to use for the user register form
    'business_card_node_form' => array('arguments' => array('form' => NULL),'template' => 'business-card-node-form',), 
    'page_node_form' => array('arguments' => array('form' => NULL),'template' => 'page-node-form',), 
  );
}

function phptemplate_preprocess_search_theme_form(&$vars, $hook) {

  // Modify elements of the search form
  $vars['form']['search_theme_form']['#title'] = t('Search mysite.com');

  // Set a default value for the search box
  $vars['form']['search_theme_form']['#value'] = t('Search');

  // Add a custom class to the search box
  $vars['form']['search_theme_form']['#attributes'] = array('class' => t('cleardefault'));

  // Change the text on the submit button
  $vars['form']['submit']['#value'] = t('Go');

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_theme_form']['#printed']);
  $vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);

  // Collect all form elements to make it easier to print the whole form.
  $vars['search_form'] = implode($vars['search']);
}



function loopriz_garland_node_preview($node) {
/*echo "<pre>";
print_r( $node );
echo "</pre>";*/
global $base_url;
$output = '<p class="create_head">Card Preview</p><div class="card_preview" id="card_preview" style="background-image:url('.$base_url."/".path_to_theme()."/images/".$node->field_card[0]['value']."_big.gif".');">
            	<span class="card_title">'.$node->name.' <br>
                	<span>'.$node->field_company_name[0]['value'].'</span>
                </span>
                <span class="card_logo">
                	<img height="140" width="142" src="'.$base_url."/".$node->field_logo[0]['filepath'].'">
                </span>';				
				$limit = sizeof($node->field_products_services) -1;
				$count = 0;
				
				foreach($node->field_products_services as $prd)
				{
				if($count < $limit)
					{
					 $products[] = $prd['value'];
					 
					 //$output .= '<span class="card_products">'.$prd['value'].'</span>';
					 $count++;
					 }
				 
				}
				$product = implode(",",$products);
				$output .= '<span class="card_products">'.$product.'</span>' ;
				
				
				$limit = sizeof($node->field_keywords) -1;
				$count = 0;
				$keywords = array();
				foreach($node->field_keywords as $prd)
				{
				if($count < $limit)
					{
				 $keywords[] = $prd['value'];
				 $count++;
				 }
				}
				$keyword = implode(",",$keywords);
				$output .='<span class="card_keyskills"><strong>Keyskills</strong><br>'.$keyword.'</span>';
            $output .='<span class="card_contactus">'.$node->field_contacts[0]['value'].'</span></div>';
			
  $output .= '<div class="preview" style="display:none;">';

  $preview_trimmed_version = FALSE;
  // Do we need to preview trimmed version of post as well as full version?
  if (isset($node->teaser) && isset($node->body)) {
    $teaser = trim($node->teaser);
    $body = trim(str_replace('<!--break-->', '', $node->body));

    // Preview trimmed version if teaser and body will appear different;
    // also (edge case) if both teaser and body have been specified by the user
    // and are actually the same.
    if ($teaser != $body || ($body && strpos($node->body, '<!--break-->') === 0)) {
      $preview_trimmed_version = TRUE;
    }
  }

  if ($preview_trimmed_version) {
    drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
    $output .= '<h3>' . t('Preview trimmed version') . '</h3>';
    $output .= node_view(drupal_clone($node), 1, FALSE, 0);
    $output .= '<h3>' . t('Preview full version') . '</h3>';
    $output .= node_view($node, 0, FALSE, 0);
  }
  else {
    $output .= node_view($node, 0, FALSE, 0);
  }
  $output .= "</div>\n";

  return $output;
}

?>
